package com.tanhua.server.utils;

import com.tanhua.domain.db.UserStateInfo;
import com.tanhua.dubbo.api.UserStateInfoApi;
import jdk.nashorn.internal.ir.annotations.Reference;
import org.springframework.stereotype.Service;

@Service
public class FreezUtils {

    @Reference
    private UserStateInfoApi userStateInfoApi;

    public  boolean isFreez(UserStateInfo state ,Integer type){

        if (state != null ) {

            if (type==state.getUserStatus()) {
                //获取解冻时间,3为永久冻结
                if (state.getExpire() == 3) {
                    //return ResponseEntity.status(500).body(ErrorResult.freezeError());
                    return false;
                }

                //计算解冻时间
                Long unfreeze = null;
                if (state.getExpire() == 1) {
                    unfreeze = state.getCreated() + 3 * 60 * 60 * 24 * 1000;
                } else {
                    unfreeze = state.getCreated() + 7 * 60 * 60 * 24 * 1000;
                }

                if (unfreeze > System.currentTimeMillis()) {
                    return false;

                } else {
                    //冷冻过期了直接删除冷冻信息
                    //userStateInfoApi.deleteStateById(state.getId());
                    return true;
                }
            }else {
                return true;
            }
        }else {
            return true;
        }
    }
}
